package cn.toolck.minitomcat.util;

public class HttpProtocolUtil {
    public static String getHttpContext200(String context) {
        StringBuilder responseStr = new StringBuilder();
        responseStr.append("HTTP/1.1 200 OK\n")
                .append("Content-Type: text/html;charset=utf-8\n")
                .append("Content-Length:" + context.length() + "\n")
                .append("\r\n")
                .append(context);
        return responseStr.toString();
    }
    public static String getHttpHead200(int length) {
        StringBuilder responseStr = new StringBuilder();
        responseStr.append("HTTP/1.1 200 OK\n")
                .append("Content-Type: text/html;charset=utf-8\n")
                .append("Content-Length:" + length + "\n")
                .append("\r\n");
        return responseStr.toString();
    }

    public static String getHttpContext404() {
        StringBuilder responseStr = new StringBuilder();
        String context = "<h1>404 not found</h1>";
        responseStr.append("HTTP/1.1 404 OK\n")
                .append("Content-Type: text/html;charset=utf-8\n")
                .append("Content-Length:" + context.length() + "\n")
                .append("\r\n")
                .append(context);
        return responseStr.toString();
    }
}
